 /**
     * 计算当前学期对象
     * @param {Array} semesters 学期列表
     * @param {String} currentDateStr 可选，指定日期
     * @returns {Object|null} 当前学期对象或最近的学期
     */
 export const getCurrentTerm = (semesters, currentDateStr) => {
    const currentDate = new Date(currentDateStr || new Date());
    const sortedSemesters = semesters
      .map((s) => ({
        ...s,
        startDateObj: new Date(s.startDate),
        endDateObj: new Date(s.endDate),
      }))
      .sort((a, b) => a.startDateObj - b.startDateObj);
    for (let sem of sortedSemesters) {
      if (currentDate >= sem.startDateObj && currentDate <= sem.endDateObj) {
        return sem;
      }
    }
    let previousSemester = null;
    for (let sem of sortedSemesters) {
      if (currentDate >= sem.endDateObj) {
        previousSemester = sem;
      } else {
        break;
      }
    }
    return previousSemester;
  };